package com.qf.service;

import com.qf.mapper.UserMapper;
import com.qf.pojo.SysUsers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author 汤奇
 * @version V1.0
 * @Project BookPro
 * @Package com.qf.service
 * @Description:
 * @Date 2022/6/14 23:41
 */
@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;

    @Override
    public SysUsers findUserByName(String username) {
        return userMapper.findUserByName(username);
    }

    @Override
    public Set<String> findRolesByUid(Integer uid) {
        List<String> roles = userMapper.findRolesByUid(uid);
        HashSet<String> set = new HashSet<>();

        if (roles != null) {
            for (String role : roles) {
                set.add(role);
            }
        }
        return set;
    }

    @Override
    public Set<String> findPermByUid(Integer uid) {
        List<String> permByUid = userMapper.findPermByUid(uid);
        HashSet<String> set = new HashSet<>();

        if (permByUid != null) {
            for (String perm : permByUid) {
                set.add(perm);
            }
        }
        return set;
    }

    @Override
    public List<SysUsers> findUserAll() {
        return userMapper.findUserAll();
    }
}
